/**
 * Created by Administrator on 2016/7/14.
 */
$(document).ready(function() {
    $("header p").click(function () {
       history.go(-1);
    })
    $(document).keypress(function(e) {
        // 回车键事件

        if(e.which == 13) {
            $(".total").css("display","none")
            var value = $("header input").val();
          if(value == ''){
              createWindow("请输入要咨询的医生姓名");
              return false;
          }else{
              $(".total").css("display","none");
              $(".header").css("display","block");
              $(".body").css("display","block");
              var name = value;

                  $.post(commonval+"/search", {
                      name: name,
                      device:"wap",
                  }, function (data) {
                      if (data.status == 0) {
                          createWindow("查询医生信息失败");
                      } else {
                          if (data.data == '') {
                              createWindow("没有符合您查询要求的医生");
                          } else {

                              $(".docListMember").css("display","block");
                              var consultList = new Vue({
                                  el: '#mainPart',
                                  data: {
                                      items: data.data.doctor_list
                                  }
                              });

                              $(".docListMember").click(function(){
                                  var id = $(this).children(".rightPart").children("p:last-child").text();
                                  location.href="doctorInfo.html?id="+id;
                              })
                          }
                      }
                  });
              }
          }
        e.stopPropagation();
    });
    //展示常用医生
    $.post(commonval+"/search_click", {
        user_token:user_token,
        device:"wap",
    }, function (data) {
        if(data.status == 1){
            console.log(data.data.doctor_list.length);
            if(data.data.doctor_list.length>3){
                $("#center").css("padding-bottom","328px");
            }
            $(".total").css("display","block");
            var dairyBook = new Vue({
                el: '#center',
                data: {
                    items: data.data.doctor_list
                }
            });
            $(".center a").click(function(){
                var id = $(this).next().text();
                location.href="doctorInfo.html?id="+id;
            })
        }else{
            createWindow("获取推荐医生失败");
        }
    });
});

//定义展示搜索结果列表方法


//定义黑色弹窗方法
function createWindow(msg) {
    var window =$("<section class='showMsg'></section>");
    var show = "<p>"+msg+"</p>";
    window.append(show);
    $("body").append(window);
    setTimeout("$('.showMsg').remove()",3000);
}


